#ifndef __TcpServer_HPP__
#define __TcpServer_HPP__

#include "Acceptor.hpp"
#include "EventLoop.hpp"
#include "TcpConnection.hpp"
#include "logger.hpp"
namespace wd
{

class TcpServer
{
public:
    TcpServer(MyLogger &mylogger,unsigned short port, const string & ip ="127.0.0.1")
    : _acceptor(port, ip)
    ,_mylogger(mylogger)
    , _loop(_acceptor,mylogger)
    {
        _acceptor.ready();
    }

    void start()
    {
        _loop.loop();
    }

    void stop()
    {
        _loop.unloop();
    }

    void setAllCallbacks(TcpConnectionCallback && cb1,
                         TcpConnectionCallback && cb2,
                         TcpConnectionCallback && cb3)
    {
        _loop.setAllCallbacks(std::move(cb1),
                              std::move(cb2),
                              std::move(cb3));
    }

private:
    Acceptor _acceptor;
    MyLogger &_mylogger;
    EventLoop _loop;
};

}//end of namespace wd


#endif

